import requests


class XmDigitalSignBaseClient():
    base_url = "https://api.zjcxjc.cn/api/v1/digital-sign"
    org_name = ""
    def request_api(self,api_url,method,data=None):
        request_url = f"{self.base_url}{api_url}"
        headers = {
            'Content-Type': 'application/json'
        }
        if method == "GET":
            response = requests.get(request_url, headers=headers,params=data)
        elif method == "POST":
            response = requests.post(request_url, json=data, headers=headers)
        if response.status_code == 200:
            return response.json()  # 返回JSON解析后的数据
        else:
            raise ValueError(f"请求失败，状态码：{response.status_code}")
    def get_signed_pdf(self,sign_order_no):
        '''获取签署文件'''
        api_url = "/get-signed-pdf"
        return self.request_api(api_url,"GET",{"orderNo":sign_order_no})
    
    def get_sign_order(self,sign_order_no):
        '''获取订单信息'''
        api_url = "/get-sign-order"
        return self.request_api(api_url,"GET",{"orderNo":sign_order_no})
    

    def create_order(self,order_info):
        '''创建订单'''
        api_url = "/create-order"
        return self.request_api(api_url,"POST",order_info)
    
    def view_signed_file(self, order_no):
        '''查看已签署文件'''
        api_url = "/get-signed-pdf"
        return self.request_api(api_url,"GET",{"orderNo":order_no})

    def get_completed_sign_records(self,order_no):
        '''获取签署记录'''
        api_url = "/get-completed_sign-records"
        return self.request_api(api_url,"GET",{"signOrderNo":order_no})
    
    def sign_coordinate_pass_time(self,dingtalkUserId,order_no):
        '''免验证时间内签署'''
        api_url = "/sign-coordinate-by-dingtalk-userid-in-pass-time"
        return self.request_api(api_url,"POST",{
            "dingtalkUserId":dingtalkUserId,
            "orderNo":order_no
        })